$(function () {
    $('.otherlogin').click(function(){
        $('.register').addClass('active').prev().removeClass('active')
        
    })
    $('.usp').click(function(){
        $('.loginon').addClass('active').next().removeClass('active')
    })

    // 点击登录
    $('.login_but').click(function(){
        var username=$('.user').val()
        var password=$('.pass').val()
        var userreg=/\d{11}/
        var passreg=/.{6,18}/
        if(userreg.test(username)==false||passreg.test(password)==false){
            layer.msg('用户名或者密码错误,用户名为11位数字，密码需输入6位以上',{
                icon:2,
                time:2000
            })
            return false
        }
        var loadindex = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
          });
        // 发送ajax请求
        $.post('./php/login.php',{
            "username":username,"password":password
        },
        function(res){
            var {meta:{status,msg},data} =res
            layer.close(loadindex);
            if(status==0){
                setCookie("keyusername",username,7)
                layer.msg(msg,{
                    icon:1,
                    time:1500
                },function(){
                    if(localStorage.getItem("url")){
                        location.href=localStorage.getItem('url')
                    }else{
                        location.href="./home.html"  
                    }   
                })
               
            }else{
                layer.msg(msg,{
                    icon:2,
                    time:1500
                })
            }

            
        },'json')

    })
    $('.logo').click(function(){
        location.href="./home.html"
    })

})